The Memory Manager provides routines to test how much memory is available. To determine the total amount of free space in the current heap zone or the size of the maximum block that could be obtained after a purge of the heap, call the PurgeSpace function.
To find out whether a Memory Manager operation finished successfully, use the MemError function.
Use the PurgeSpace procedure to determine the total amount of free memory and the size of the largest allocatable block after a purge of the heap.
PROCEDURE PurgeSpace (VAR total: LongInt; VAR contig: LongInt);
The PurgeSpace procedure returns, in the total parameter, the total amount of space (in bytes) that could be obtained after a general purge of the current heap zone; this amount includes space that is already free. In the contig parameter, PurgeSpace returns the size of the largest allocatable block in the current heap zone that could be obtained after a purge of the zone.
The PurgeSpace procedure does not actually purge the current heap zone.
To find out whether your application's last direct call to a Memory Manager routine executed successfully, use the MemError function.
FUNCTION MemError: OSErr;
The MemError function returns the result code produced by the last Memory Manager routine your application called directly.
This function is useful during application debugging. You might also use the function as one part of a memory-management scheme to identify instances in which the Memory Manager rejects overly large memory requests by returning the error code memFullErr .
Do not rely on the MemError function as the only component of a memory-management scheme. For example, suppose you call NewHandle or NewPtr and receive the result code noErr , indicating that the Memory Manager was able to allocate sufficient memory. In this case, you have no guarantee that the allocation did not deplete your application's memory reserves to levels so low that simple operations might cause your application to crash. Instead of relying on MemError , check before making a memory request that there is enough memory both to fulfill the request and to support essential operations.
Because most Memory Manager routines return a result code in register D0, you do not ordinarily need to call the MemError function if you program in assembly language. See the description of an individual routine to find out whether it returns a result code in register D0. If not, you can examine the global variable MemErr . When MemError returns, register D0 contains the result code.